/**
* Mule Constant Contact Connector
*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
/**
* This file was automatically generated by the Mule Development Kit
*/
package org.mule.modules.constantcontact;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.http.HttpStatus;
import org.mule.api.ConnectionException;
import org.mule.api.annotations.Configurable;
import org.mule.api.annotations.Connect;
import org.mule.api.annotations.ConnectionIdentifier;
import org.mule.api.annotations.Connector;
import org.mule.api.annotations.Disconnect;
import org.mule.api.annotations.Processor;
import org.mule.api.annotations.ValidateConnection;
import org.mule.api.annotations.param.ConnectionKey;
import org.mule.api.annotations.param.Default;
import org.mule.api.annotations.param.Optional;
import org.mule.modules.constantcontact.api.ConstantContactApi;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;
/**
* Constant Contact is an online marketing company serving small businesses, nonprofit organizations, and membership
* associations. The company offers email marketing, social media marketing, online survey, and event marketing tools.
*
* @author MuleSoft, Inc.
*/
@Connector(name = "constantcontact")
public class ConstantContactConnector implements ConstantContactApi<ConstantContactException> {
/**
* The API key provided by Constant Contact
*/
@Configurable
private String apiKey;
private ConstantContactClient client;
private Resources resources;
private String username;
/**
* Retrieves the collection of activities for the current username. Response is made up of a feed element which
* contains some metadata about the feed followed by a series of entry elements. Each entry is made up of some
* metadata followed by a content element. Inside the content element is a Activity element which describes the
* attributes of a particular activity. To retrieve the details of a particular activity use {@link this#getActivity(String)}
* using the link element with rel="edit" attribute.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getActivities}
*
* @return the collection of activities for the current username
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Bulk-Activity-Collection-of-Activities/ba-p/25105">Retrieving a Collection of Activities</a>
*/
@Processor
@Override
public Feed getActivities() throws ConstantContactException {
return client.doGetRequest(resources.activitiesCollection());
}
/**
* Creates an export contacts activity.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:createExportContactsActivity}
*
* @param listId The list the data is exported from. The list should be a list id URI as referenced in {@see http://community.constantcontact.com/t5/Documentation/Contact-List-Members-Collection/ba-p/25093}. System defined lists, such as 'do-not-mail' are supported.
* @param fileType Type of file to be exported
* @param exportOptDate true to include the Add/Remove Date in the export file, false to not include it
* @param exportOptSource true to include the Added/Removed By (source of add or remove) in the export file, false to not include it
* @param exportListName true to include the List Name in the export file, false to not include it
* @param sortBy EMAIL_ADDRESS to sort the list by email address in ascending order. DATE_DESC will sort the contacts by the Date in descending order
* @param columns list of which optional fields to include in the exported file. (EMAIL ADDRESS is always included in the exported file). The names are the same as those used in files for upload.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Creating-an-Export-Contacts-Activity/ba-p/25037">Creating an Export Contacts Activity</a>
*/
@Processor
@Override
public void createExportContactsActivity(String listId, FileType fileType, Boolean exportOptDate, Boolean exportOptSource, Boolean exportListName, SortBy sortBy, List<Column> columns) throws ConstantContactException {
// TODO there are more activities to implement
client.doPostRequest(resources.exportContactsActivity(listId, fileType, exportOptDate, exportOptSource, exportListName, sortBy, columns));
}
/**
* Retrieves an individual activity entry. The link may be obtained from the Location header after creating a new
* entry or from the link element with rel="edit" attribute in an existing entry.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getActivity}
*
* @param activityIdOrLink an existing activity id or a URI pointing to an existing activity.
* @return the activity denoted by the given activity id or link
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Bulk-Activity-Collection-of-Activities/ba-p/25105">Retrieving the Details of an Individual Activity</a>
*/
@Processor
@Override
public Feed getActivity(String activityIdOrLink) throws ConstantContactException {
return client.doGetRequest(resources.activityResource(activityIdOrLink));
}
/**
* The campaigns collection refers to a group of campaigns available to a particular user.
* Returns a list of campaigns as described in {@see http://community.constantcontact.com/t5/Documentation/Campaigns-Collection/ba-p/25111}.
* Each campaign is returned in <entry> tags, and if there are multiple campaigns, there will be multiple <entry> elements.
* Each entry provides only the basic information about a campaign, such as the name or title of the campaign, its author and status.
* To get more details for a particular campaign, you need to use the <link> provided inside <entry> and call {@link this#getCampaign(String)}
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getCampaigns}
*
* @param campaignStatus restrict the results to a given {@link CampaignStatus}, if not specified all campaigns will be returned
* @return A sequence of <entry> elements each representing a campaign
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Campaigns-Collection/ba-p/25111">Campaigns Collection</a>
*/
@Processor
@Override
public Feed getCampaigns(@Optional CampaignStatus campaignStatus) throws ConstantContactException {
return client.doGetRequest(resources.campaignsCollection(campaignStatus));
}
/**
* Returns the details of a campaign as described in {@see http://community.constantcontact.com/t5/Documentation/Campaigns-Collection/ba-p/25111}.
* The response body would return XML elements according to {@see http://community.constantcontact.com/t5/Documentation/Campaign-Resource/ba-p/25109}.
* The details should include whether the campaign is based on templates or custom HTML/XHTML, whether the campaign
* is HTML or XHTML based if it's based on custom code, the campaign's status, details of the email itself, and
* settings on "View As Webpage" or "Permission Reminder" features. In addition, the campaign detail includes the
* status and URL for the archived pages.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getCampaign}
*
* @param campaignId a campaign id or a link obtained by {@link this#getCampaigns(CampaignStatus)}
* @return the campaign details as described in {@see http://community.constantcontact.com/t5/Documentation/Campaigns-Collection/ba-p/25111}
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Obtaining-a-Campaign-s-Information/ba-p/25049">Obtaining a Campaign's Information</a>
*/
@Processor
@Override
public Feed getCampaign(String campaignId) throws ConstantContactException {
return client.doGetRequest(resources.campaignDetails(campaignId));
}
/**
* Removes the campaign represented by the given campaign id or link obtained by {@link this#getCampaigns(CampaignStatus)}.
* This operation is the same as removing a campaign from the UI and will exclude the removed campaign from overall statistics.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:deleteCampaign}
*
* @param campaignIdOrLink a campaign id or a link obtained by {@link this#getCampaigns(CampaignStatus)}
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Scheduling-and-Sending-a-Campaign/ba-p/25113">Removing a Campaign</a>
*/
@Processor
@Override
public void deleteCampaign(String campaignIdOrLink) throws ConstantContactException {
client.doDeleteRequest(resources.campaignDetails(campaignIdOrLink));
}
/**
* Creates a new campaign
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:createCampaign}
*
* @param campaignName Name for the Campaign
* @param subject Subject line for the email
* @param fromName The name that is displayed in the from box in the recipients email client
* @param fromEmail Email address entry represents From address shows the address that the email originated from
* @param replyToEmail Email address entry represents the field used by an email client's reply function
* @param viewAsWebPage This allows contacts who cannot view images in their email program to open your email in a browser window.
* @param viewAsWebpageLinkText The text for the actual link in the View As Webpage link in the email
* @param viewAsWebageText The text displayed together with the LinkText at the top of your email
* @param permissionReminder Whether to show a permission reminder at the top of the email allowing recipients to confirm their opt in.
* @param permissionReminderText Text to be displayed if PermissionReminder is set to Yes. Should be left blank if PermissionReminder is set to No.
* @param greetingSalutation Describes the chosen salutation to be used at the opening of the email (e.g. Dear)
* @param greetingName Indicates if the email greeting should include just the recipient's FirstName, just the LastName, Both, or neither and use GreetingString instead.
* @param greetingString Allows you to specify the full greeting string instead of the components of the previous two properties. If GreetingName and GreetingString are populated, they will be used instead of GreetingString.
* @param organizationName Name of organization for use in the email footer
* @param organizationAddress1 Line 1 of the organization address for use in the email footer
* @param organizationAddress2 Line 2 of the organization address for use in the email footer
* @param organizationAddress3 Line 3 of the organization address for use in the email footer
* @param organizationCity City of the organization for use in the email footer
* @param organizationState State of the organization for use in the email footer
* @param organizationInternationalState International "State" if outside the US for use in the email footer
* @param organizationPostalCode PostalCode/Zipcode of the organization for use in the email footer
* @param organizationCountry Country of the organization for use in the email footer
* @param includeForwardEmail Boolean type property that indicates if the email should include a Forward This Email link
* @param forwardEmailLinkText if IncludeForwardEmail property is set to YES, then this property should be specified and will appear in the email as the text of the link
* @param includeSubscribeLink Boolean type property that indicates if the email should include a Subscribe link
* @param subscribeLinkText If IncludeSubscribeLink property is set to YES, then this property should be specified and will appear in the email as the text of the link
* @param emailContentFormat Describes whether email content is based on HTML or XHTML.
* @param emailContent The full HTML/XHTML content of the email
* @param emailTextContent The text version of the email content. Will be used for email clients that do not have HTML email capability or have it disabled
* @param styleSheet The stylesheet elements that are used for the email content.
* @param contactLists Collection of ContactList entries that are associated with this email Campaign
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Creating-a-Campaign/ba-p/25047">Creating a Campaign</a>
*/
@Processor
@Override
public void createCampaign(String campaignName,
String subject,
String fromName,
String fromEmail,
String replyToEmail,
Boolean viewAsWebPage,
String viewAsWebpageLinkText,
String viewAsWebageText,
Boolean permissionReminder,
String permissionReminderText,
String greetingSalutation,
GreetingName greetingName,
String greetingString,
String organizationName,
String organizationAddress1,
String organizationAddress2,
String organizationAddress3,
String organizationCity,
String organizationState,
String organizationInternationalState,
String organizationPostalCode,
String organizationCountry,
Boolean includeForwardEmail,
String forwardEmailLinkText,
Boolean includeSubscribeLink,
String subscribeLinkText,
EmailContentFormat emailContentFormat,
String emailContent,
String emailTextContent,
String styleSheet,
List<String> contactLists) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
// TODO: add @Optional or @Default
// String fromEmailEntry = client.extractEmail(getContactsByEmailAddress(Arrays.asList(fromEmail)));
// String replyToEmailEntry = client.extractEmail(getContactsByEmailAddress(Arrays.asList(replyToEmail)));
// String createCamapignRequest = new CampaignRequestBuilder().
// setName(name).
// setSubject(subject).
// setFromName(fromName).
// setFromEmail(fromEmailEntry).
// setReplyToEmail(replyToEmailEntry).
// setViewAsWebPage(viewAsWebPage).
// setViewAsWebpageLinkText(viewAsWebpageLinkText).
// setViewAsWebageText(viewAsWebageText).
// setPermissionReminder(permissionReminder).
// setPermissionReminderText(permissionReminderText).
// setGreetingSalutation(greetingSalutation).
// setGreetingName(greetingName).
// setGreetingString(greetingString).
// setOrganizationName(organizationName).
// setOrganizationAddress1(organizationAddress1).
// setOrganizationAddress2(organizationAddress2).
// setOrganizationAddress3(organizationAddress3).
// setOrganizationCity(organizationCity).
// setOrganizationState(organizationState).
// setOrganizationInternationalState(organizationInternationalState).
// setOrganizationPostalCode(organizationPostalCode).
// setOrganizationCountry(organizationCountry).
// setIncludeForwardEmail(includeForwardEmail).
// setForwardEmailLinkText(forwardEmailLinkText).
// setIncludeSubscribeLink(includeSubscribeLink).
// setSubscribeLinkText(subscribeLinkText).
// setEmailContentFormat(emailContentFormat).
// setEmailContent(emailContent).
// setEmailTextContent(emailTextContent).
// setStyleSheet(styleSheet).
// setContactLists(contactLists).build();
// try {
// client.doPostRequest(resources.createCampaign(createCamapignRequest));
// } catch (UnsupportedEncodingException e) {
// throw new ConstantContactException("Error while encoding the HTTP Post request body: " + createCamapignRequest, e);
// }
}
/**
* Updates a campaign by passing the updated campaign {@link Feed} obtained by calling {@link this#getCampaign(String)}
* You can update both template-based campaign and custom-code campaign. For template-based campaign, you can only
* update properties associated with the campaign, but not the actual email content itself. For custom-code campaign,
* you can update properties as well as update the HTML/XHTML associated with the campaign. A campaign can only be
* updated in DRAFT status.
* For a custom-code campaign, <EmailContent> is required. If you have <EmailContent> in your request but do not
* have any values, then the content of the campaign will be deleted. If <EmailContent> element is not included in
* the XML, then the HTML content of the campaign will not be touched.
* When updating a campaign, you can change values of elements that are marked as editable in http://community.constantcontact.com/t5/Documentation/Campaigns-Collection/ba-p/25111}
* IMPORTANT: Any editable elements that do not have any values specified during an update will overwrite any existing
* values with an empty field
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateCampaign}
*
* @param campaign the updated campaign {@link Feed}
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Updating-a-Campaign/ba-p/25045">Updating a Campaign</a>
*/
@Processor
@Override
public void updateCampaign(Feed campaign) throws ConstantContactException {
client.doPutRequest(resources.updateFeed(campaign));
}
/**
* The Campaign Events service provides access to the detailed results (Open, Click, Bounce and other Events)
* associated with any Campaign (email) sent in the last 90 days. It helps answer these kinds of question: What
* Contacts Opened my last email? What links in the Campaign did they Click On? When did the Contact perform the action?
* The events include sends, opens, opt-outs (unsubscribes), clicks, bounces, and forwards.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getCampaignEvents}
*
* @param campaignId the id of the campaign to get the events for
* @return the campaign events
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Campaign-Events-Resource/ba-p/25107">Campaign Events Resource</a>
*/
@Processor
@Override
public Feed getCampaignEvents(String campaignId) throws ConstantContactException {
return client.doGetRequest(resources.campaignEvents(campaignId));
}
/**
* Returns a list of all contacts in your account. Each contact is returned in <entry> element, and if there are
* more than one contact in the account, there will be mutliple <entry> returned. Each <entry> provides only the
* basic information about a contact.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContacts}
*
* @return a list of all contacts in your account
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Listing-All-Contacts/ba-p/25061">Listing All Contacts</a>
*/
@Processor
@Override
public Feed getContacts() throws ConstantContactException {
return client.doGetRequest(resources.contacts());
}
/**
* This functionality allows you to keep your contacts database up-to-date with the latest information from the
* Constant Contact database by querying only the updated contacts since your specified date. The last updated date
* of a contact will change if any of its details have been updated or its contact list membership has changed.
* Please note, however, that the search results do not specify what kind of updates have been made to each contact;
* we just know that they have been updated since the time you specified and return correspoding contacts accordingly.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContactsByListType}
*
* @param updatedSince search for updates later than this date
* @param listType the type of list to search updates
* @return the contacts that match the given starting date and are part of the list type.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Searching-for-Contacts-by-Last-Updated-Date-Synchronizing/ba-p/25053">Searching for Contacts by Last Updated Date (Synchronizing Contacts)</a>
*/
@Processor
@Override
public Feed getContactsByListType(Date updatedSince, ListType listType) throws ConstantContactException {
return client.doGetRequest(resources.contactsByListType(updatedSince, listType));
}
/**
* This functionality allows you to keep your contacts database up-to-date with the latest information from the
* Constant Contact database by querying only the updated contacts since your specified date. The last updated date
* of a contact will change if any of its details have been updated or its contact list membership has changed.
* Please note, however, that the search results do not specify what kind of updates have been made to each contact;
* we just know that they have been updated since the time you specified and return correspoding contacts accordingly.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContactsByListId}
*
* @param updatedSince search for updates later than this date
* @param listId the numeric value of the list you are interested in searching
* @return the contacts that match the given starting date and are part of the list with the given id.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Searching-for-Contacts-by-Last-Updated-Date-Synchronizing/ba-p/25053">Searching for Contacts by Last Updated Date (Synchronizing Contacts)</a>
*/
@Processor
@Override
public Feed getContactsByListId(Date updatedSince, String listId) throws ConstantContactException {
return client.doGetRequest(resources.contactsByListId(updatedSince, listId));
}
/**
* Returns the XML body that describes a contact's full detail, the information includes contact details as well as
* contact lists to which the contact belongs. You may pass the contact's id or URI for the contact resource by
* using {@link this#getContacts()} and looking for the <link> element with attribute rel="edit" in the desired
* contact <entry>
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContact}
*
* @param contactId the contact id or link
* @return the contact details
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Obtaining-a-Contact-s-Information/ba-p/25057">Obtaining a Contact's Information</a>
*/
@Processor
@Override
public Feed getContact(String contactId) throws ConstantContactException {
return client.doGetRequest(resources.contactDetails(contactId));
}
/**
* Finds a particular contact by its email address.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContactsByEmailAddress}
*
* @param emailAddresses one or more email address to search
* @return one or more contact details depending on the number of email addresses provided
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Searching-for-a-Contact-by-Email-Address/ba-p/25123">Searching for a Contact by Email Address</a>
*/
@Processor
@Override
public Feed getContactsByEmailAddress(List<String> emailAddresses) throws ConstantContactException {
try {
return client.doGetRequest(resources.contactDetails(emailAddresses));
} catch (UnsupportedEncodingException e) {
throw new ConstantContactException("Error while URL encoding the email address list: " + emailAddresses, e);
}
}
/**
* Creates a contact.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:createContact}
*
* @param emailAddress the email address to add, 80 characters max
* @param contactLists indicates which lists the Contact belongs to, the contact must be included in AT LEST one list
* @param optInSource use {@link OptInSource#ACTION_BY_CONTACT} if the contact is adding himself or herself, use {@link OptInSource#ACTION_BY_CUSTOMER} if you are adding the contacts on their behalf
* @param emailType the preferred type of email
* @param firstName the contact's first name, 50 characters max
* @param middleName the contact's middle name, 50 characters max
* @param lastName the contact's last name, 50 characters max
* @param jobTitle the contact's job title, 50 characters max
* @param companyName the contact's company name, 50 characters max
* @param homePhone the contact's home phone, 50 characters max
* @param workPhone the contact's work phone, 50 characters max
* @param address1 the contact's address 1, 50 characters max
* @param address2 the contact's address 2, 50 characters max
* @param address3 the contact's address 3, 50 characters max
* @param city the contact's city, 50 characters max
* @param stateCode the contact's state code, must be a valid US/Canada State Code and must be consistent with CountryCode. 2 characters max as listed in http://ui.constantcontact.com/CCSubscriberAddFileFormat.jsp#states
* @param stateName the contact's state name, 50 characters max
* @param countryCode the contact's country code, must be a valid two character, lower case, Country Code. See: http://constantcontact.custhelp.com/cgi-bin/constantcontact.cfg/php/enduser/std_adp.php?p_faqid=3614
* @param countryName the contact's country name, 50 characters max
* @param postalCode the contact's postal code, 25 characters max
* @param subPostalCode the contact's sub postal code, 25 characters max
* @param note customer notes field. This field should only be visible to the Customer but not to the Contact.
* @param customFieldValues up to 15 custom field values, each custom field value is 50 characters max
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Creating-a-Contact/ba-p/25059">Creating a Contact</a>
*/
@Processor
@Override
public void createContact(@Size(max = 80) String emailAddress,
@Size(min = 1) List<String> contactLists,
@Optional @Default("ACTION_BY_CUSTOMER") OptInSource optInSource,
@Optional EmailType emailType,
@Size(max = 50) @Optional String firstName,
@Size(max = 50) @Optional String middleName,
@Size(max = 50) @Optional String lastName,
@Size(max = 50) @Optional String jobTitle,
@Size(max = 50) @Optional String companyName,
@Size(max = 50) @Optional String homePhone,
@Size(max = 50) @Optional String workPhone,
@Size(max = 50) @Optional String address1,
@Size(max = 50) @Optional String address2,
@Size(max = 50) @Optional String address3,
@Size(max = 50) @Optional String city,
@Pattern(regexp = "[A-Z]{2}") @Optional String stateCode,
@Size(max = 50) @Optional String stateName,
@Optional String countryCode,
@Size(max = 50) @Optional String countryName,
@Size(max = 25) @Optional String postalCode,
@Size(max = 25) @Optional String subPostalCode,
@Optional String note,
@Size(max = 15) @Optional List<String> customFieldValues) throws ConstantContactException {
String createContactRequest = new ContactRequestBuilder().
setEmailAddress(emailAddress).
setOptInSource(optInSource).
setFirstName(firstName).
setMiddleName(middleName).
setLastName(lastName).
setJobTitle(jobTitle).
setCompanyName(companyName).
setHomePhone(homePhone).
setWorkPhone(workPhone).
setAddress1(address1).
setAddress2(address2).
setAddress3(address3).
setCity(city).
setStateCode(stateCode).
setStateName(stateName).
setCountryCode(countryCode).
setCountryName(companyName).
setPostalCode(postalCode).
setSubPostalCode(subPostalCode).
setNote(note).
setCustomFieldValues(customFieldValues).
setContactLists(contactLists).build();
try {
client.doPostRequest(resources.createContact(createContactRequest));
} catch (UnsupportedEncodingException e) {
throw new ConstantContactException("Error while encoding the HTTP Post request body: " + createContactRequest, e);
}
}
/**
* Updates the details of for the given contact
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateContact}
*
* @param updatedContact a {@link Feed} containing exactly one entry with the updated details of the contact
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Updating-Contact-Information/ba-p/25055">Updating Contact Information</a>
*/
@Processor
@Override
public void updateContact(Feed updatedContact) throws ConstantContactException {
List<Entry> entries = updatedContact.getEntries();
if (entries.isEmpty()) {
throw new ConstantContactException("Provided feed does not contain any entry: " + updatedContact);
}
if (entries.size() > 1) {
throw new ConstantContactException("Provided feed contains more than one entry: " + updatedContact);
}
client.doPutRequest(resources.updateContact(updatedContact));
}
/**
* Removing a contact does not mean that the contact has unsubscribed or opted out of receiving emails. It means
* the contact simply does not belong to any particular contact list, and can be added back to a list by the
* account owner. However, this API should not be used if the contact has unsubscribed from receiving all emails.
* Instead, you must opt-out the contact.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:deleteContact}
*
* @param contactIdOrLink the id or link of the contact to delete
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Removing-a-Contact/ba-p/25119">Removing a Contact</a>
*/
@Processor
@Override
public void deleteContact(String contactIdOrLink) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
// TODO: according to docs a contact is removed by removing all the contact lists from it
}
/**
* Returns the campaign events for the given contact
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getContactCampaignEvents}
*
* @param contactId the id of the contact for which to get the campaign events
* @return the campaign events
* @throws ConstantContactException in case of error
*/
@Processor
@Override
public Feed getContactCampaignEvents(String contactId) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Contacts who have opted out of receiving all mails and have been placed on Do-Not-Mail list must opt themselves
* in. The account owner cannot add a contact in Do-Not-Mail list back to a different list. The action must be
* initiated by the contact. It is a serious violation of the Constant Contact Terms of Service to use the Opt-in
* features of the API in any other way (i.e. opting in a contact without his or her action and consent).
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:optInContact}
*
* @param contact tbd
* @param listToOptIn tbd
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Opting-in-a-Contact/ba-p/25115">Opting-in a Contact</a>
*/
@Processor
@Override
public void optInContact(Feed contact, String listToOptIn) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Opting-out a contact means that contact has decided to unsubscribe from receiving all emails or has asked to stop
* sending all emails. Opted-out contacts become members of the {@link ListType#DO_NOT_MAIL} special list and is
* removed from all other contact lists.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:optOutContact}
*
* @param contactId the contact id or link
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Opting-out-a-Contact/ba-p/25117">Opting-out a Contact</a>
*/
@Processor
@Override
public void optOutContact(String contactId) throws ConstantContactException {
client.doDeleteRequest(resources.contactDetails(contactId), HttpStatus.SC_NO_CONTENT);
}
/**
* Returns a list of events that are currently in your account. The list of events contains a set of summary data
* that is useful to see at a glance, but in order to see more details, you need to get the details of individual events.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEvents}
*
* @return a list of events that are currently in your account.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Events/ba-p/25099">Obtaining a List of Events</a>
*/
@Processor
@Override
public Feed getEvents() throws ConstantContactException {
return client.doGetRequest(resources.events());
}
/**
* Adds a new event.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:addEvent}
*
* @param needToDefineThis tbd
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Events/ba-p/25099">Creating an Event</a>
*/
@Processor
@Override
public void addEvent(String needToDefineThis) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* Returns the event details for the given event id or event URI. The detail data for each event is very complex and
* contains a lot of information. The complete structure structure of event can be found in
* {@see http://community.constantcontact.com/t5/Documentation/Events-Collection-and-Resource/ba-p/25081}
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEvent}
*
* @param eventId the event id or event URI
* @return the event details
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Events/ba-p/25099">Obtaining Details of an Event</a>
*/
@Processor
@Override
public Feed getEvent(String eventId) throws ConstantContactException {
return client.doGetRequest(resources.eventDetails(eventId));
}
/**
* Updates a event.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateEvent}
*
* @param needToDefineThis event data TBD
* @throws ConstantContactException in case of error
*/
@Processor
@Override
public void updateEvent(String needToDefineThis) throws ConstantContactException {
throw new UnsupportedOperationException("Not implemented yet");
}
/**
* The list contains a list of registrants only and does not include guests as a separate entry. In other words,
* the list returned by this API represents the list of registrants as they appear on our UI page, which does not
* include guests. The only available data for guests is the number of guests each registrant is bringing to the
* event, but we will soon be releasing an API for obtaining more detailed guest information as well.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrants}
*
* @param eventId the event id for which to get the registrants for
* @return the list of registrants for event represented by the given id
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Obtaining a List of Registrants for an Event</a>
*/
@Processor
@Override
public Feed getEventRegistrants(String eventId) throws ConstantContactException {
return client.doGetRequest(resources.eventRegistrants(eventId));
}
/**
* The registrant resource represents individual registrants that exist in the user account. The registrant detail
* includes all of the personal and business information of the registrant, the answers to the custom questions and
* payment information.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrantDetails}
*
* @param eventId the event id or event URI
* @param registrantId the registrant id or registrant URI
* @return the registrant details as described in {@see http://community.constantcontact.com/t5/Documentation/Registrants-Collection-and-Resource/ba-p/25079}
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Obtaining Details of a Registrant</a>
*/
@Processor
@Override
public Feed getEventRegistrantDetails(String eventId, String registrantId) throws ConstantContactException {
return client.doGetRequest(resources.eventRegistrantDetails(eventId, registrantId));
}
/**
* Many events allow attendees to invite guests. Programmers can obtain a list of guests invited by a given attendee
* (formally, a 'registrant').
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrantGuests}
*
* @param eventId the event id
* @param registrantId the registrant id
* @return the guests for the given registrant in the given event
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Obtaining A List of Guests</a>
*/
@Processor
@Override
public Feed getEventRegistrantGuests(String eventId, String registrantId) throws ConstantContactException {
return client.doGetRequest(resources.eventRegistrantGuests(eventId, registrantId));
}
/**
* Return the details of a given guest.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrantGuestDetails}
*
* @param eventId the vent id or event URI
* @param registrantId the registrant id or registrant URI
* @param guestId the guest id or guest URI
* @return the guest details
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Obtaining Guest Details</a>
*/
@Processor
@Override
public Feed getEventRegistrantGuestDetails(String eventId, String registrantId, String guestId) throws ConstantContactException {
return client.doGetRequest(resources.guestDetails(eventId, registrantId, guestId));
}
/**
* Retrieves the attendance status for registrant represented by the given registrant id or registrant URI.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrantAttendanceStatus}
*
* @param eventId the event id or event URI
* @param registrantId the registrant id or registrant URI
* @return the attendance status for the given registrant
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Attendance Status</a>
*/
@Processor
@Override
public Feed getEventRegistrantAttendanceStatus(String eventId, String registrantId) throws ConstantContactException {
return client.doGetRequest(resources.attendanceStatus(eventId, registrantId));
}
/**
* Updates the attendance status for the given {@link Feed} that represents an event registrant.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateEventRegistrantAttendanceStatus}
*
* @param feed the {@link Feed} representing an event registrant
* @param attendanceStatus the new {@link AttendanceStatus} for the event registrant
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Updating Attendance Status</a>
*/
@Processor
@Override
public void updateEventRegistrantAttendanceStatus(Feed feed, AttendanceStatus attendanceStatus) throws ConstantContactException {
// TODO implement
}
/**
* Returs the payment status for the registrant represented by the given registrant id or registrant URI.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getEventRegistrantPaymentStatus}
*
* @param eventId the event id or event URI
* @param registrantId the registrant id or registrant URI
* @return the payment status for the given registrant
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Payment Status</a>
*/
@Processor
@Override
public Feed getEventRegistrantPaymentStatus(String eventId, String registrantId) throws ConstantContactException {
return client.doGetRequest(resources.paymentStatus(eventId, registrantId));
}
/**
* Updates the payment status for the given {@link Feed} that represents an event registrant.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateEventRegistrantPaymentStatus}
*
* @param feed the {@link Feed} representing an event registrant
* @param paymentStatus the new {@link PaymentStatus} for the event registrant
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Managing-Registrants-and-Guests/ba-p/25097">Update Payment Status</a>
*/
@Processor
@Override
public void updateEventRegistrantPaymentStatus(Feed feed, PaymentStatus paymentStatus) throws ConstantContactException {
List<Entry> entries = feed.getEntries();
if (entries.isEmpty()) {
throw new ConstantContactException("Provided feed does not contain any entry: " + feed);
}
if (entries.size() > 1) {
throw new ConstantContactException("Provided feed contains more than one entry: " + feed);
}
client.doPutRequest(resources.updateEventRegistrantPaymentStatus(feed, paymentStatus));
}
/**
* Retrieves the collection of contact lists for the current username
* The response is made up of a feed element which contains some metadata about the feed followed by a series of
* entry elements. Each entry is made up of some metadata followed by a content element. Inside the content element
* is a ContactList element which describes the attributes of a particular contact list.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getMailingLists}
*
* @return the contact lists for the current username
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Retrieving-a-Contact-List-Collection/ba-p/25067">Retrieving a Contact List Collection</a>
*/
@Processor
@Override
public Feed getMailingLists() throws ConstantContactException {
return client.doGetRequest(resources.mailingLists());
}
/**
* Creates a new mailing list.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:createMailingList}
*
* @param optInDefault if true, Contacts who sign-up or change their settings may add themselves to this list.
* @param listName the list name
* @param sortOrder relative position of this Contact List in the full set of Contact Lists. The values are arbitrary relative values. A List with SortOrder=25 will be shown after a List with Sort Order 15.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Creating-a-New-List/ba-p/25069">Creating a New List</a>
*/
@Processor
@Override
public void createMailingList(Boolean optInDefault, String listName, Integer sortOrder) throws ConstantContactException {
String createMailingListRequest = new ListRequestBuilder().
setOptInDefault(optInDefault).
setName(listName).
setSortOrder(sortOrder).build();
try {
client.doPostRequest(resources.mailingList(createMailingListRequest));
} catch (UnsupportedEncodingException e) {
throw new ConstantContactException("Error while encoding the HTTP Post request body: " + createMailingListRequest, e);
}
}
/**
* Retrieves an individual mailing list represented by the given mailing list id or mailing list URI.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getMailingList}
*
* @param mailingListId the mailing list id or mailing list URI
* @return the mailing list details as described in {@see http://community.constantcontact.com/t5/Documentation/Contact-List-Resource/ba-p/25043}
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Retrieving-an-Individual-List/ba-p/25065">Retrieving an Individual List</a>
*/
@Processor
@Override
public Feed getMailingList(String mailingListId) throws ConstantContactException {
return client.doGetRequest(resources.mailingListDetails(mailingListId));
}
/**
* Updates the mailing list. The {@link org.apache.abdera.model.Feed) provided MUST contain and Atom entry element
* with the changed content for the list. The Atom entry must include an <id> tag and that id must reflect the URI
* of the list you are updating. As a general rule, your entry should include all of the content you receive by
* calling {@link this#getMailingList(String)} for the resource you are updating. The simplest way to update a list
* is to call {@link this#getMailingList(String)} to "GET" the resource you would like to update, then change only
* the fields you want to update and "PUT" the updated resource back. The API will ignore read only fields (such as
* update time) and your entry will be complete.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:updateMailingList}
*
* @param feed a {@link org.apache.abdera.model.Feed) containing exactly one entry with the mailing list details.
* @throws ConstantContactException in case the provided {@link org.apache.abdera.model.Feed) does not containt EXACTLY one entry
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Updating-a-List/ba-p/25063">Updating a List</a>
*/
@Processor
@Override
public void updateMailingList(Feed feed) throws ConstantContactException {
List<Entry> entries = feed.getEntries();
if (entries.isEmpty()) {
throw new ConstantContactException("Provided feed does not contain any entry: " + feed);
}
if (entries.size() > 1) {
throw new ConstantContactException("Provided feed contains more than one entry: " + feed);
}
client.doPutRequest(resources.updateFeed(feed));
}
/**
* Deletes the mailing list represented by the given mailing list id or mailing list URI
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:deleteMailingList}
*
* @param mailingListId the mailing list id or mailing uri
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Contact-List-Resource/ba-p/25043">Deleting a List</a>
*/
@Processor
@Override
public void deleteMailingList(String mailingListId) throws ConstantContactException {
client.doDeleteRequest(resources.mailingListDetails(mailingListId), HttpStatus.SC_NO_CONTENT);
}
/**
* The Contact List Members collection is used to list Contacts within a specific list.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getMailingListMembers}
*
* @param mailingListId the id of the list to get the members for
* @return the contact list members
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Contact-List-Members-Collection/ba-p/25093">Contact List Members Collection</a>
*/
@Processor
@Override
public Feed getMailingListMembers(String mailingListId) throws ConstantContactException {
return client.doGetRequest(resources.mailingListMembers(mailingListId));
}
/**
* The account settings email address collection allows you to retrieve a list of registered email addresses on your
* account as specified in the Settings in the UI. These email addresses are used in conjunction with campaign
* resource to specify From Email and Reply To email addresses.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getAccountEmailAddresses}
*
* @return A sequence of <entry> elements each representing an email address registered with the account.
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Account-Email-Addresses-Collection/ba-p/25091">getAccountEmailAddresses()</a>
*/
@Processor
@Override
public Feed getAccountEmailAddresses() throws ConstantContactException {
return client.doGetRequest(resources.accountEmailAddressCollection());
}
/**
* The account settings email address collection allows you to retrieve a list of registered email addresses on your
* account as specified in the Settings in the UI. These email addresses are used in conjunction with campaign
* resource to specify From Email and Reply To email addresses.
* <p/>
* {@sample.xml ../../../doc/constantcontact-connector.xml.sample constantcontact:getAccountEmailAddress}
*
* @param emailId the id or the link of the email adrress obtained by {@link this#getAccountEmailAddresses()}
* @return A sequence of <entry> elements each representing an email address registered with the account or null if no address exists with the given id
* @throws ConstantContactException in case of error
* @api.doc <a href="http://community.constantcontact.com/t5/Documentation/Account-Email-Addresses-Resource/ba-p/25089">Account Email Addresses Resource</a>
*/
@Processor
@Override
public Feed getAccountEmailAddress(String emailId) throws ConstantContactException {
return client.doGetRequest(resources.accountEmailAddressResource(emailId));
}
/**
* Connect
*
* @param username A username
* @param password A password
* @throws ConnectionException
*/
@Connect
public void connect(@ConnectionKey String username, String password) throws ConnectionException {
this.username = username;
resources = new Resources(username);
client = new ConstantContactClient(apiKey, username, password);
}
/**
* Disconnect
*/
@Disconnect
public void disconnect() {
client = null;
}
/**
* Are we connected
*/
@ValidateConnection
public boolean isConnected() {
return client != null;
}
/**
* Are we connected
*/
@ConnectionIdentifier
public String connectionId() {
return "username=" + username;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getApiKey() {
return apiKey;
}
}